document.addEventListener("DOMContentLoaded", function () {
    document.getElementById("loginForm").addEventListener("submit", function (event) {
        event.preventDefault();

        let formData = new FormData(this);

        fetch("Ajax/login.php", {
            method: "POST",
            body: formData
        })
        .then(response => response.json())
        .then(data => {
            if (data.status === "success") {
                window.location.href = "panel.html"; // Redirige al panel de control
            } else {
                alert(data.message);
            }
        })
        .catch(error => console.error("Error:", error));
    });
});
